import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../main.dart';
import '../../../r.dart';
import '../../../utils/logger_utils.dart';
import '../../../values/MyColors.dart';
import '../../../widget/ImagesGridviewWidget.dart';
import 'complete_poll_logic.dart';

/// 完成调研
class CompletePollPageIpad extends StatefulWidget {
  final String title;

  const CompletePollPageIpad({Key? key, required this.title}) : super(key: key);

  @override
  State<CompletePollPageIpad> createState() => _CompletePollPageIpadState();
}

class _CompletePollPageIpadState extends State<CompletePollPageIpad> {
  final logic = Get.put(CompletePollLogic());
  final state = Get.find<CompletePollLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<CompletePollLogic>(builder: (logic) {
      return OrientationBuilder(builder: (context, orientation) {
        return Scaffold(
          backgroundColor: MyColors.FFEDF1F5,
          appBar: BrnAppBar(title: "填写证明资料", themeData: XxxConfigUtils.defaultAppBarConfig),
          body: Stack(
            children: [
              Image.asset(orientation == Orientation.portrait ? R.assetsImgBgHome3Ipad : R.assetsImgBgHome3IpadL,
                  fit: BoxFit.fill, width: Get.width, height: 210.r),
              SizedBox(
                height: Get.height,
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      Center(
                        child: Column(
                          children: [
                            Padding(
                              padding: EdgeInsets.only(top: 40.r),
                              child: Image.asset(R.assetsImgIconHome9, width: 52.r),
                            ),
                            Padding(
                              padding: EdgeInsets.only(top: 11.r),
                              child: Text("答卷已经提交，感谢您的参与!", style: TextStyle(color: Colors.white, fontSize: 13.r)),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 42.r),
                        decoration: BoxDecoration(
                          color: MyColors.FFEDF1F5,
                          borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(10.r),
                            topRight: Radius.circular(10.r),
                          ),
                        ),
                        child: Column(
                          children: [
                            Visibility(
                              visible: state.isSignature,
                              child: Container(
                                margin: EdgeInsets.fromLTRB(12.r, 16.r, 12.r, 6.r),
                                padding: EdgeInsets.only(left: 10.r, right: 10.r),
                                height: 36.r,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(3.r)),
                                ),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text("受访者签名", style: TextStyle(color: MyColors.FF333333, fontSize: 10.r, fontWeight: FontWeight.bold)),
                                    Visibility(
                                      visible: state.image.isNotEmpty,
                                      child: Image.memory(state.image, width: 75.r),
                                    ),
                                    SizedBox(
                                      width: 60.r,
                                      height: 22.r,
                                      child: BrnNormalButton(
                                        text: '点击签名',
                                        fontSize: 10.r,
                                        textColor: Colors.white,
                                        backgroundColor: MyColors.FF1060DD,
                                        insertPadding: const EdgeInsets.all(0),
                                        alignment: Alignment.center,
                                        borderRadius: BorderRadius.circular(2.r),
                                        onTap: () {
                                          logic.goToSignature();
                                        },
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            Visibility(
                              visible: state.isVideo,
                              child: Container(
                                margin: EdgeInsets.fromLTRB(12.r, 0.r, 12.r, 12.r),
                                padding: EdgeInsets.only(left: 10.r, right: 10.r, top: 11.r, bottom: 13.5.r),
                                width: Get.width,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(3.r)),
                                ),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text("与被访者合照", style: TextStyle(color: MyColors.FF333333, fontSize: 10.r, fontWeight: FontWeight.bold)),
                                    Container(
                                      padding: EdgeInsets.only(top: 12.5.r),
                                      child: ImagesGridviewWidget(
                                        onMediaResultsCallback: (List<Media> imagesList, filePathList) {
                                          state.imagesList = imagesList;
                                        },
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
          bottomNavigationBar: SafeArea(
            child: Container(
              height: 36.r,
              margin: EdgeInsets.only(left: 12.r, right: 12.r, bottom: 12.r, top: 12.r),
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  padding: const EdgeInsets.all(0),
                  backgroundColor: MyColors.FF0144B0,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.r))),
                ),
                child: Text("完成调研", style: TextStyle(color: Colors.white, fontSize: 12.r)),
                onPressed: () {
                  logic.complete();
                },
              ),
            ),
          ),
        );
      });
    });
  }

  @override
  void dispose() {
    Get.delete<CompletePollLogic>();
    super.dispose();
  }
}
